<template>
	<view class="content">
		<view class="list b-b" v-for="(item, index) in addressList" :key="index" @click="chooseAdd(item)">

			<view class="wrapper">
				<view class="address-box">
					<text v-if="item.is_default==1" class="tag">默认</text>
					<text class="address">{{item.province}} {{item.city}} {{item.area}} {{item.address}}</text>
				</view>
				<view class="u-box">
					<text class="name">{{item.name}}</text>
					<text class="mobile">{{item.mobile}}</text>
					<image class="yticon" src="../../static/useCenter/address/edit.png" mode="widthFix" @click.stop="addAddress('edit', item)"></image>
				</view>
			</view>
		</view>
		<!-- <text style="display:block;padding: 16upx 30upx 10upx;lihe-height: 1.6;color: #fa436a;font-size: 24upx;">
			重要：添加和修改地址回调仅增加了一条数据做演示，实际开发中将回调改为请求后端接口刷新一下列表即可
		</text>
		 -->
		<button class="add-btn" @click="addAddress('add')">新增收货地址</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				addressList: []
			}
		},
		onLoad() {
			this.getAddress();
		},
		methods: {
			chooseAdd(item){
				this.$api.prePage().orderData.addressVo = item;
				uni.navigateBack()
			},
			getAddress(){
				const {$http,$requestApi} = this;
				$http
					.request({
						method: 'POST', // 请求方法必须大写
						url: $requestApi.getAllAddress,
						data: {
							pageNo:1
						}
					})
					.then(result => {
						let _data = result.data;
						if (_data.code === 200) {
							this.addressList = _data.result.list;
						}
					})
					.catch(err => {
						console.log(err);
					});
			},
			
			
			addAddress(type, item) {
				
				uni.navigateTo({
					url: `/pages/address/addressManage?type=${type}&data=${JSON.stringify(item)}`
				})
			},
			//添加或修改成功之后回调
			refreshList() {
				this.getAddress();
			}
		}
	}
</script>

<style lang='scss'>
	page {
		padding-bottom: 120upx;
	}

	.content {
		position: relative;
		
	}
	.b-b:after{
			left: 30upx;
		}
	.list {
		display: flex;
		align-items: center;
		padding: 36upx;
		background: #fff;
		position: relative;
	}

	.wrapper {
		display: flex;
		flex-direction: column;
		flex: 1;
	}

	

	.address-box {
		display: flex;
		align-items: flex-start;

		.tag {
			font-size: 24upx;
			color: #fff;
			margin-right: 10upx;
			background: $base-color2;
			border-radius: 8upx;
			width: 76upx;
			height: 36upx;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-top: 6upx;

		}

		.address {
			font-size: 30upx;
			color: $font-color-dark;
			max-width: 460upx;
		}
	}

	.u-box {
		font-size: 28upx;
		color: $font-color-light;
		position:relative;
		.name {
			margin-right: 30upx;
		}
		.yticon {
			width: 34upx;
			height: auto;
			position: absolute;
			right: 0;
		}
	}

	.add-btn {
		position: fixed;
		left: 30upx;
		right: 30upx;
		bottom: 16upx;
		z-index: 95;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		font-size: 32upx;
		color: #fff;
		border-radius: 49upx;
		background: linear-gradient(86deg, rgba(255, 94, 0, 1) 0%, rgba(255, 35, 0, 1) 100%);
		box-shadow: 0upx 10upx 30upx rgba(255, 68, 0, 0.2);
	}
</style>
